Release 10.1A: OpenEdge Development:
Programming Interfaces
Specifying joins in the 4GL
Progress supports two types of joins in the 4GL:
- Inner join — Supported in all statements capable of reading multiple tables, including the
FOR,DO,REPEAT, andOPENQUERYstatements. An inner join returns the records selected for the table (or join) on the left side combined with the related records selected from the table on the right. For any records not selected from the right-hand table, the join returns no records from either the left or right sides of the join. Thus, only related records that are selected from both sides are returned for an inner join. Table 1–3 shows an example of inner joins.Note: For Progress versions earlier than V8, Progress supports only the inner join.- Left outer join — Supported only in the
OPENQUERYstatement. A left outer join returns the records selected for an inner join. In addition, for each set of records selected from the table (or join) on the left side, a left outer join returns the Unknown value (?) from the table on the right where there is no record selected or otherwise related to the records on the left. That is, records from the left-hand table (or join) are preserved for all unmatched records in the right-hand table. Figure 1–4 shows an example of left outer joins using the same tables as in Figure 1–3.Specifying the type of join
The Record phrase that specifies the right-hand table of a join also indicates the type of join operation. A Record phrase specifies an inner join by default. To specify a left outer join, you include the [
LEFT]OUTER–JOINoption anywhere in the Record phrase. Where you specify a list of multiple Record phrases in a record-reading statement, the join logic allows you to specify only one set of contiguous inner joins at the beginning (left side) of the list and one set of contiguous left outer joins at the end (right side) of the list. Each right-hand Record phrase of a left outer join must contain theOUTER–JOINoption up to and including the last left outer join in the list. For more information, see the "Mixing inner and left outer joins" section.Relating and selecting tables
You can specify join conditions (table relations) using the
Note: Work tables and temporary tables can also participate in joins. However, work tables do not have indexes. So, if you specify join conditions using theOFoption orWHEREoption of the Record phrase that specifies the join. TheOFoption specifies an implicit join condition based on one or more common field names in the specified tables. The common field names must participate in a unique index for at least one of the tables. TheWHEREoption can specify an explicit join based on any field relations you choose, and you can use this option further to specify selection criteria for each table in the join. For an inner join, if you do not use either option, Progress returns a join of all records in the specified tables. For a left outer join, you must relate tables and select records using theOFoption, theWHEREoption, or both options.OFoption with a work table, the other table in the join must be a database or temporary table with a unique index for the fields in common. For more information on work tables and temporary tables, see OpenEdge Development: Progress 4GL Handbook .The following code fragment generates the left outer joins shown in Figure 1–4. Note that the Record phrase for the right-hand table of each join specifies the
OUTER–JOINoption. As Figure 1–4 shows, the primary benefit of a left outer join is that it returns every record on the left-hand side, whether or not related data exists on the right:
Figure 1–4: Left outer joins
![]()
Why use joins instead of nested reads?
Using joins provides an opportunity for Progress to optimize the retrieval of records from multiple related tables using the selection criteria you specify. When you perform a nested read, for example using nested
FOREACHstatements for different tables, you are actually implementing a join in a 4GL procedure. However, by specifying one or more contiguous joins in a singleFOREACHstatement or in thePRESELECTphrase of singleDOorREPEATstatement, you minimize the complexity of your 4GL code and leave the complexity of joining tables to the Progress interpreter.For a single 4GL query (
OPENQUERYstatement), there is no other way to retrieve data from multiple tables except by using joins. With both inner and left outer join capability, you can use theOPENQUERYstatement to implement most queries that are possible using nestedFOREACH,DO, orREPEATstatements. As such, query joins provide the greatest opportunity for optimized multi-table record retrieval in the 4GL. Also, because browse widgets read their data from queries, you must use query joins to display multiple related tables in a browse. (For more information on browsing records, see OpenEdge Development: Progress 4GL Handbook .)However, use nested
FOREACH,DO, andREPEATblocks wherever you require much finer control over how you access and manipulate records from multiple tables.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |